//
//  MJTableView.m
//  XhlTrip
//
//  Created by dllo on 15/8/29.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//
#import "MJTableView.h"

@interface MJTableView ()

@property (nonatomic, assign) id myDelegate;

@end

@implementation MJTableView

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style delegate:(id)delegate {
    self = [super initWithFrame:frame style:style];
    if (self) {
        _myDelegate = delegate;
        [self setupRefresh];
    }
    return self;
}

- (void)setDelegateWithNib:(id)delegate {
    _myDelegate = delegate;
    [self setupRefresh];
}

- (void)setupRefresh {
    // 下拉刷新
    [self addHeaderWithTarget:self action:@selector(headerRereshing) dateKey:@"table"];
    
    // 上拉加载更多(进入刷新状态就会调用self的footerRereshing)
    [self addFooterWithTarget:self action:@selector(footerRereshing)];
    
    //一些设置
    // 设置文字(也可以不设置,默认的文字在MJRefreshConst中修改)
    self.headerPullToRefreshText = @"下拉可以刷新了";
    self.headerReleaseToRefreshText = @"松开马上刷新了";
    self.headerRefreshingText = @"刷新中。。。";
    
    self.footerPullToRefreshText = @"上拉可以加载更多数据了";
    self.footerReleaseToRefreshText = @"松开马上加载更多数据了";
    self.footerRefreshingText = @"加载中。。。";
}

- (void)headerRereshing {
    if ([_myDelegate respondsToSelector:NSSelectorFromString(@"refreshingHeader:")]) {
        [_myDelegate refreshingHeader:self];
    }
    [self headerEndRefreshing];
}

- (void)footerRereshing {
    if ([_myDelegate respondsToSelector:NSSelectorFromString(@"refreshingFooter:")]) {
        [_myDelegate refreshingFooter:self];
    }
    [self footerEndRefreshing];
}

- (void)headerBeginRefresh {
    [self headerBeginRefreshing];
}


- (void)removeHeaderView {
    [self removeHeader];
}

- (void)removeFooterView {
    [self removeFooter];
}


@end
